/*
 * @Descripttion:  路由
 * @Author: maybe
 * @Date: 2019-06-24 17:51:21
 */
import Vue from 'vue'
import Router from 'vue-router'
import store from './../store'  
// 首页
import Home from '@/page/home/Home'  

// 交易模块
import Transaction from '@/page/transaction/Transaction'
import TransactionIndex from '@/page/transaction/children/Index'
import HisOrder from  '@/page/transaction/children/HisOrder'  // 历史交易记录
import OrderDetail from '@/page/transaction/children/OrderDetail' //订单详情

// 用户模块
import Login from '@/page/Login'
import MobileLogin from '@/page/mobileLogin'
import Register from '@/page/Register'
import ForgetPassword from '@/page/ForgetPassword'
// import Authentication from '@/page/user/authentication' //实名

// 个人中心
import Personal from '@/page/user/personal' // 个人中心主界面。公用左边导航
import PersonalIndex from '@/page/user/children/index' // 默认页面，个人信息
import Bank from '@/page/user/children/bankCard'  // 银行卡
import Account from '@/page/user/children/account' // 账户信息
import BankDetail from '@/page/user/children/bankDetail' // 银行卡详情
import AddBank from '@/page/user/children/AddBank' // 银行卡详情
import RechargeRecord from '@/page/user/children/rechargeRecord' //充值记录
import WithdrawRecord from '@/page/user/children/withdrawRecord' //提现记录
import OrderRecord from '@/page/user/children/orderRecord' //订单交易记录
import RealName from '@/page/user/children/realName'  // 实名
import Recharge from '@/page/user/children/recharge' // 充值入金
import Withdraw from '@/page/user/children/withdraw' //提现出金
import ReNotice from '@/page/user/children/renotice' //充值需知

Vue.use(Router)
const router =  new Router({
  mode:'history',
  routes: [
    {
      path: '/home',   // 网站首页
      name: 'Home',
      component: Home,
      meta:{hideHeader:true,title:'期权交易-交易中心'} 
    },{
      path: '/transaction',   // 交易页面
      component: Transaction,    
      children: [
        {
          path:'index',
          name:'TransactionIndex',
          component:TransactionIndex,
          meta:{isLogin:true,hideHeader:true,title:'期权交易-交易中心'} 
        },{
          path:'hisOrder',
          name:'HisOrder',
          component:HisOrder,
          meta:{isLogin:true,hideHeader:true,title:'期权交易-交易中心'}  //体现记录
        },{
          path:'orderDetail',
          name:'OrderDetail',
          component:OrderDetail,
          meta:{isLogin:true,hideHeader:true,title:'期权交易-订单详情'}  //体现记录
        },     
        {path:'/',redirect:'/transaction/index'}
      ]
    },
    {
        path:'/user',
        component:Personal,
        children:[
          {
            path:'index',
            name:'PersonalIndex',
            component:PersonalIndex,
            meta:{isLogin:true,title:'期权交易-个人信息'} 
          },{
            path:'bank',
            name:'BankCard',
            component:Bank,
            meta:{isLogin:true,title:'期权交易-银行卡'} 
          },{
            path:'bankDetail',
            name:'BankDetail',
            component:BankDetail,
            meta:{isLogin:true,title:'期权交易-银行卡详情'} 
          },{
            path:'bankAdd',
            name:'bankAdd',
            component:AddBank,
            meta:{isLogin:true,title:'期权交易-添加银行卡'}
          },{
            path:'account',
            name:'Account',
            component:Account,
            meta:{isLogin:true,title:'期权交易-账户信息'} 
          },{
            path:'realName',
            name:'RealName',
            component:RealName,
            meta:{isLogin:true,title:'期权交易--实名认证'}
          },{
            path:'recharge',
            name:'Recharge',
            component:Recharge,
            meta:{isLogin:true,title:'期权交易--实名认证'}
          },{
            path:'reNotice',
            name:'ReNotice',
            component:ReNotice,
            meta:{isLogin:true,title:'期权交易--实名认证'}
          },{
            path:'withdraw',
            name:'Withdraw',
            component:Withdraw,
            meta:{isLogin:true,title:'期权交易--实名认证'}
          },{
            path:'rechargeRecord',
            name:'RechargeRecord',
            component:RechargeRecord,
            meta:{isLogin:true,title:'期权交易-添加银行卡'}
          },{
            path:'withdrawRecord',
            name:'WithdrawRecord',
            component:WithdrawRecord,
            meta:{isLogin:true,title:'期权交易-添加银行卡'}
          },{
            path:'orderRecord',
            name:'OrderRecord',
            component:OrderRecord,
            meta:{isLogin:true,title:'期权交易-添加银行卡'}
          },
          {path:'/',redirect:'/user/index'} 
        ]
           
    },{
      path: '/login',   // 登陆
      name: 'Login',
      component: Login,
      meta:{title:"期权交易-登陆"}
    },{
      path: '/mobileLogin',   // 登陆
      name: 'MobileLogin',
      component: MobileLogin,
      meta:{title:"期权交易-登陆"}
    },{
      path: '/register',  // 注册
      name: 'Register',
      component: Register,
      meta:{title:"期权交易-注册账户"}
    },{
      path: '/forgetPassword',  // 忘记密码
      name: ForgetPassword,
      component: ForgetPassword,
      meta:{title:"期权交易-找回密码"}
    },
    {path:'*', redirect:'/home'}   // 路由转向，招不到路由默认路由 },   
  ]
})


// 设置路由守卫  后期备用
router.beforeEach((to, from, next) => {
  // to: Route: 即将要进入的目标 路由对象
  // from: Route: 当前导航正要离开的路由
  // next: Function: 一定要调用该方法来 resolve 这个钩子。执行效果依赖 next 方法的调用参数。
   if(to.meta.title){
     document.title = to.meta.title;
   }
  if(to.meta.isLogin && store.state.userId === ""){
      router.replace({path:'/login'});
  }
   next();
})

router.afterEach( route => {
 
  
})





export default router;